import { ScrollView } from "@tarojs/components";
import ByPopupBottom, {
  ByPopupBottomEvent,
} from "@/components/ui/ByPopupBottom";
import ByStepsItem from "@/components/ui/ByStepsItem";
import useFetch from "@/hooks/useFetch";
import ApiBalance from "@/api/balance";
import ListView from "@/components/app/ListView";

export default ({
  intentCustomerId,
  onCancel,
}: { intentCustomerId } & ByPopupBottomEvent) => {

  const { loading, data } = useFetch<{ records: any[] }>(ApiBalance.records, {
    defaultParams: [{ intentCustomerId }],
  });

  const list = data?.records || [];
  return (
    <>
      <ByPopupBottom title="记录" onCancel={onCancel}>
        <ScrollView className="px-6 h-[70vh]" scrollY>
          <ListView loading={loading} isEmpty={list.length == 0}>
            {list.map((item) => (
              <ByStepsItem
                key={item.timestamp}
                title={item.source + " " + item.action}
                date={item.timeStr}
              />
            ))}
          </ListView>
        </ScrollView>
      </ByPopupBottom>
    </>
  );
};
